/*
  Copyright (c) 2010 by HierOS
  This file is part of M8J project
*/
#include "history.h"
#include <stdio.h>
#include "mzfc\uilist.h"

void History::appendHistory() {
	int nIndex;
	ListItem * pItem = GetItem(nIndex);
	CMessageItemData * pItemData = (CMessageItemData*)pItem->Data;
	CMzString historyPath;
	std::wstring filePath=historyPath;
	filePath+='\\';
	filePath+= pItemData->Jid;
	filePath+=L".txt";
	std::wstring str_time = pItemData->DateStr + L' ';
	str_time += pItemData->TimeStr;
	if (pItemData->MessageType == MessageReceived)
	{
		std::wstring in_out = L">>>";
	}
	else if (pItemData->MessageType == MessageSent)
	{
		std::wstring in_out = L"<<<";	
	}


	FILE *f=_wfopen(filePath.c_str(), L"a");
	if (f==NULL) return;
	fwprintf(f, L"---%s---\n %s (%s):\n%s\n", in_out.c_str(), pItemData->Name.c_str(), str_time.c_str(), pItemData->MessageText.c_str());
	fclose(f);
}

History::History() {
   		CMzString historyPath;
		historyPath=GetMyPath()+L"\\History";
		CreateDirectory(historyPath, NULL);
}
